﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}

<script src="~/Content/adminDefault/js/default.js"></script>
<script>
    var WIDTH = "", _TypeId = "";
    $(function () {
        InitialPage();
        GetTree();
        GetGrid();
        WIDTH = $('.gridPanel').width();
    });
    function BaseClick(ss) {
        if (ss == 0) {
            GetGrid();
            $('#gridTable').setGridWidth(($('.gridPanel').width() < 1 ? WIDTH : $('.gridPanel').width()));
        }
        else if (ss == 1) {
            GetGrid1();
            $('#gridTable2').setGridWidth(($('.gridPanel').width() < 1 ? WIDTH : $('.gridPanel').width()));
        }
        else if (ss == 2) {
            GetGrid2();
            $('#gridTable3').setGridWidth(($('.gridPanel').width() < 1 ? WIDTH : $('.gridPanel').width()));
        }
    }
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 165.5);
            }, 200);
            e.stopPropagation();
        });
    }
    //种类树
    function GetTree() {
        var item = {
            height: $(window).height() - 55.5,
            url: "../../ResourceManage/RS_DeviceType/GetTreeJson",
            onnodeclick: function (item) {
                _TypeId = item.id;
                $('#btn_Search').trigger("click");
                $('#btn_Search2').trigger("click");
                $('#btn_Search3').trigger("click");
            }
        };
        //初始化
        $("#itemTree").treeview(item);
    }
    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            url: "../../ResourceManage/RS_DeviceType/GetListJson",
            postData: {
                condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
                keyword: $("#txt_Keyword").val(),
                DeviceTypeId: _TypeId
            },
            datatype: "json",
            height: $(window).height() - 165.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", hidden: true },
                { label: "类别编号", name: "Code", index: "Code", width: 100, align: "center", sortable: false },
                { label: "类别名称", name: "Name", index: "Name", width: 200, align: "center", sortable: false },
                { label: "描述", name: "Description", index: "Description", width: 100, align: "center", sortable: false }
            ],
            viewrecords: true,
            treeGrid: true,
            treeGridModel: "nested",
            ExpandColumn: "Name",
            rowNum: "all",
            rownumbers: true,
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            $gridTable.jqGrid('setGridParam', {
                url: "../../ResourceManage/RS_DeviceType/GetListJson",
                postData: {
                    DeviceTypeId: _TypeId,
                    condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
                    keyword: $("#txt_Keyword").val()
                }
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }
    function GetGrid1() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable2');
        var queryJson = {};
        queryJson["condition"] = $("#queryCondition1").find('.dropdown-text').attr('data-value');
        queryJson["keyword"] = $("#txt_Keyword").val();
        queryJson["TypeId"] = _TypeId;
        $gridTable.jqGrid({
            url: "../../ResourceManage/RS_DeviceType/GetDatasListJson",
            postData: {
                queryJson: JSON.stringify(queryJson)
            },
            datatype: "json",
            height: $(window).height() - 181.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", hidden: true },
                { label: "设备种类", name: "TypeName", index: "TypeName", width: 100, align: "center" },
                { label: "参数名称", name: "Name", index: "Name", width: 100, align: "center" },
                {
                    label: "参数类型", name: "ValueType", index: "ValueType", width: 100, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case "text": return "文本";
                            case "number": return "数值";
                            default: return "";
                        }
                    }
                },
                { label: "参数标准", name: "Criterition", index: "Criterition", width: 100, align: "center" },
                { label: "参数标准值", name: "Value", index: "Value", width: 100, align: "center" },
                { label: "默认值", name: "DefaultValue", index: "DefaultValue", width: 100, align: "center" },
                {
                    label: "数据来源类型", name: "DataSourceType", index: "DataSourceType", width: 100, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case "1": return "录入";
                            case "2": return "统计";
                            case "3": return "词典";
                            default: return "";
                        }
                    }
                },
                {
                    label: "是否必填", name: "Required", index: "Required", width: 100, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == 0 ? "<i value=" + cellvalue + " class=\"fa fa-toggle-on\"></i>" : "<i value=" + cellvalue + " class=\"fa fa-toggle-off\"></i>";
                    }
                }
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortable: true,
            sortname: 'SortCode',
            sortorder: 'asc',
            rownumbers: true,
            shrinkToFit: true,
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询条件
        $("#queryCondition1 .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition1 .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search2").click(function () {
            var queryJson = {};
            queryJson["condition"] = $("#queryCondition1").find('.dropdown-text').attr('data-value');
            queryJson["keyword"] = $("#txt_Keyword").val();
            queryJson["TypeId"] = _TypeId;
            $gridTable.jqGrid('setGridParam', {
                url: "../../ResourceManage/RS_DeviceType/GetDatasListJson",
                postData: {
                    queryJson: JSON.stringify(queryJson)
                },
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search2').trigger("click");
            }
        });

        $("#lr-replaceDatas").click(function () {
            $gridTable.jqGrid('setGridParam', {
                url: "../../ResourceManage/RS_DeviceType/GetDatasListJson"
            }).trigger('reloadGrid');
        });
    }
    function GetGrid2() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable3');
        var queryJson = {};
        queryJson["condition"] = $("#queryCondition2").find('.dropdown-text').attr('data-value');
        queryJson["keyword"] = $("#txt_Keyword").val();
        queryJson["TypeId"] = _TypeId;
        $gridTable.jqGrid({
            url: "../../ResourceManage/RS_DeviceType/GetPartsListJson",
            postData: {
                queryJson: JSON.stringify(queryJson)
            },
            datatype: "json",
            height: $(window).height() - 181.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", index: "Name", width: 100, align: "center", hidden: true },
                { label: "零配件名称", name: "Name", index: "Name", width: 100, align: "center" },
                { label: "生产厂商", name: "Factory", index: "Factory", width: 100, align: "center" },
                { label: "规格型号", name: "ModelNo", index: "ModelNo", width: 100, align: "center" },
                { label: "价格", name: "Price", index: "Price", width: 100, align: "center" },
                { label: "附加说明", name: "Description", index: "Description", width: 200, align: "center" }
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager1",
            sortable: true,
            sortname: 'Id',
            sortorder: 'asc',
            rownumbers: true,
            shrinkToFit: true,
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询条件
        $("#queryCondition2 .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition2 .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search3").click(function () {
            var queryJson = {};
            queryJson["condition"] = $("#queryCondition2").find('.dropdown-text').attr('data-value');
            queryJson["keyword"] = $("#txt_Keyword").val();
            queryJson["TypeId"] = _TypeId;
            $gridTable.jqGrid('setGridParam', {
                url: "../../ResourceManage/RS_DeviceType/GetPartsListJson",
                postData: {
                    queryJson: JSON.stringify(queryJson)
                },
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search3').trigger("click");
            }
        });


        $("#lr-replaceParts").click(function () {
            $gridTable.jqGrid('setGridParam', {
                url: "../../ResourceManage/RS_DeviceType/GetPartsListJson",
            }).trigger('reloadGrid');
        });
    }
    //新增
    function btn_add() {
        dialogOpen({
            id: "Form",
            title: '新增设备种类',
            url: '/ResourceManage/RS_DeviceType/Form',
            width: "800px",
            height: "500px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    };
    //编辑
    function btn_edit() {
        
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '编辑设备种类',
                url: '/ResourceManage/RS_DeviceType/Form?keyValue=' + keyValue,
                width: "800px",
                height: "500px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    };
    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (keyValue) {
            $.RemoveForm({
                url: "../../ResourceManage/RS_DeviceType/RemoveForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的单据！', 0);
        }
    }

    //新增设备参数
    function btn_addDatas() {
        dialogOpen({
            id: "DatasForm",
            title: '新增设备参数',
            url: '/ResourceManage/RS_DeviceType/DatasForm',
            width: "800px",
            height: "500px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    }
    function btn_editDatas() {
        var keyValue = $("#gridTable2").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '编辑设备参数',
                url: '/ResourceManage/RS_DeviceType/DatasForm?keyValue=' + keyValue,
                width: "800px",
                height: "500px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    }
    function btn_deleteDatas() {
        var keyValue = $("#gridTable2").jqGridRowValue("Id");
        if (keyValue) {
            $.RemoveForm({
                url: "../../ResourceManage/RS_DeviceType/RemoveDatasForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable2").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的参数！', 0);
        }
    }

    //新增设备零配件
    function btn_addParts() {
        dialogOpen({
            id: "PartsForm",
            title: '新增设备零配件',
            url: '/ResourceManage/RS_DeviceType/PartsForm',
            width: "800px",
            height: "500px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    }
    function btn_editParts() {
        
        var keyValue = $("#gridTable3").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "PartsForm",
                title: '编辑设备零配件',
                url: '/ResourceManage/RS_DeviceType/PartsForm?keyValue=' + keyValue,
                width: "800px",
                height: "500px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    }
    function btn_deleteParts() {
        var keyValue = $("#gridTable3").jqGridRowValue("Id");
        if (keyValue) {
            $.RemoveForm({
                url: "../../ResourceManage/RS_DeviceType/RemovePartsForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable3").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的参数！', 0);
        }
    }
</script>

<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel">
            <div class="panel-Title" style="padding:0px;">设备种类</div>
            <div id="itemTree"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <ul class="nav nav-tabs" style="background-color:#f6f8f8;">
                <li class="active" onclick="BaseClick(0)">
                    <a href="#panel1" data-toggle="tab">设备种类</a>
                </li>
                <li onclick="BaseClick(1)">
                    <a href="#panel2" data-toggle="tab">设备参数</a>
                </li>
                <li onclick="BaseClick(2)">
                    <a href="#panel3" data-toggle="tab">设备零配件</a>
                </li>
            </ul>
            <div class="tab-content">
                <div class="tab-pane active" id="panel1">
                    <div class="titlePanel">
                        <div class="title-search">
                            <table>
                                <tr>
                                    <td>
                                        <div class="btn-group" id="queryCondition">
                                            <a class="btn btn-default dropdown-text" data-toggle="dropdown">选择条件</a>
                                            <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                                            <ul class="dropdown-menu">
                                                <li><a data-value="Code">编号</a></li>
                                                <li><a data-value="Name">名称</a></li>
                                            </ul>
                                        </div>
                                    </td>
                                    <td style="padding-left: 2px;">
                                        <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                                    </td>
                                    <td style="padding-left: 5px;">
                                        <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <div class="toolbar">
                            <div class="btn-group">
                                <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                                <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                                <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                                <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                            </div>
                            <script>$('.toolbar').authorizeButton()</script>
                        </div>
                    </div>
                    <div class="gridPanel">
                        <table id="gridTable"></table>
                    </div>
                </div>
                <div class="tab-pane" id="panel2">
                    <div class="titlePanel">
                        <div class="title-search">
                            <table>
                                <tr>
                                    <td>
                                        <div class="btn-group" id="queryCondition1">
                                            <a class="btn btn-default dropdown-text" data-toggle="dropdown">选择条件</a>
                                            <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                                            <ul class="dropdown-menu">
                                                <li><a data-value="Name">名称</a></li>
                                            </ul>
                                        </div>
                                    </td>
                                    <td style="padding-left: 2px;">
                                        <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                                    </td>
                                    <td style="padding-left: 5px;">
                                        <a id="btn_Search2" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <div class="toolbar">
                            <div class="btn-group">
                                <a id="lr-replaceDatas" class="btn btn-default" ><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                                <a id="lr-addDatas" class="btn btn-default" onclick="btn_addDatas()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                                <a id="lr-editDatas" class="btn btn-default" onclick="btn_editDatas()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                                <a id="lr-deleteDatas" class="btn btn-default" onclick="btn_deleteDatas()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                            </div>
                            <script>$('.toolbar').authorizeButton()</script>
                        </div>
                    </div>
                    <div class="gridPanel">
                        <table id="gridTable2"></table>
                        <div id="gridPager"></div>
                    </div>
                </div>
                <div class="tab-pane" id="panel3">
                    <div class="titlePanel">
                        <div class="title-search">
                            <table>
                                <tr>
                                    <td>
                                        <div class="btn-group" id="queryCondition2">
                                            <a class="btn btn-default dropdown-text" data-toggle="dropdown">选择条件</a>
                                            <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                                            <ul class="dropdown-menu">
                                                <li><a data-value="Name">名称</a></li>
                                            </ul>
                                        </div>
                                    </td>
                                    <td style="padding-left: 2px;">
                                        <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                                    </td>
                                    <td style="padding-left: 5px;">
                                        <a id="btn_Search3" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <div class="toolbar">
                            <div class="btn-group">
                                <a id="lr-replaceParts" class="btn btn-default" ><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                                <a id="lr-addParts" class="btn btn-default" onclick="btn_addParts()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                                <a id="lr-editParts" class="btn btn-default" onclick="btn_editParts()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                                <a id="lr-deleteParts" class="btn btn-default" onclick="btn_deleteParts()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                            </div>
                            <script>$('.toolbar').authorizeButton()</script>
                        </div>
                    </div>
                    <div class="gridPanel">
                        <table id="gridTable3"></table>
                        <div id="gridPager1"></div>
                    </div>
                </div>
            </div>


        </div>
    </div>
</div>